package com.lagou.rpc.consumer.utils;

import com.lagou.rpc.consumer.client.RpcClient;

import java.util.*;

public class ServerRegister {

    static int i = 0;

    static List<Map<String, Object>> serverList = new ArrayList<>();

    static {
        Map<String, Object> map_8897 = new HashMap<>();
        map_8897.put("id", "127.0.0.1");
        map_8897.put("port", 8897);
        serverList.add(map_8897);

        Map<String, Object> map_8898 = new HashMap<>();
        map_8898.put("id", "127.0.0.1");
        map_8898.put("port", 8898);
        serverList.add(map_8898);

        Map<String, Object> map_8899 = new HashMap<>();
        map_8899.put("id", "127.0.0.1");
        map_8899.put("port", 8899);
        serverList.add(map_8899);
    }

    public synchronized static RpcClient getRpcClient() {
        if (i >= serverList.size()) i = 0;
        Map<String, Object> map = serverList.get(i++);
        RpcClient client = new RpcClient(String.valueOf(map.get("id")), Integer.parseInt(String.valueOf(map.get("port"))));
        System.out.println(map);
        return client;
    }
}
